package sala 
{
	import flash.display.AVM1Movie;
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.net.URLLoader;
	import flash.net.URLRequest;
	import flash.text.TextField;
	import sala.commonmovie.bottommenu.BottomMenuContainer;
	import sala.commonmovie.mainmenu.MainMenu;
	import sala.commonmovie.rightmenu.RightMenu;
	import sala.commonmovie.textmanager.TextContainer;
	import sala.commonmovie.video.VideoPlayer;
	import sala.components.VerScroll;
	import sala.events.MainMenuEvent;
	import sala.events.RightMenuEvent;
	import sala.model.AlbumInfo;
	import sala.model.VideoInfo;
	import sala.events.BottomMenuEvent;
	import gs.TweenLite; 
	import flash.utils.setTimeout;
	import sala.common.Configuration; 
	import sala.events.TextTweenEvent; 
	
	/**
	 * ...
	 * @author Sun
	 */
	public class Sala extends MovieClip
	{
		public var mainMenu: MainMenu;
		public var rightMenu: RightMenu;
		public var videoPlayer: VideoPlayer;
		public var textContainerMc:TextContainer; 
		public var bottomMenuContainerMc:BottomMenuContainer; 
		public var thumbMaskMc:MovieClip; 
		public var textMaskMc:MovieClip; 
		public var rightMenuMaskMc:MovieClip; 
		public var rightVLineMc:MovieClip; 
		
		public var faceMc:MovieClip; 
		public var trackMc:MovieClip; 
		
		public var shortVLineMc:MovieClip; 
			
		public var textContainHeader:TextField; 
		
		private var albumInfoArr: Array;
		public var headerArr:Array; 
		
		private var menuItemName:String;
		
		private var verScroll: VerScroll;
		private var verScrollMainMenu: VerScroll;
		private var verScrollRightMenu: VerScroll;
		public function Sala() 
		{
			lock();
			LanguageManager.setLanguage("viet"); 
			
			menuItemName = "aboutusMc";
			
			setTimeout(playRightMenuAnim, 2000); 
			setTimeout(tweenInMainText, 1000); 
			setTimeout(showThumbStrip, 4000); 
			
			//this.rightMenu.mask = thumbMaskMc; 
			//this.textContainerMc.mask = textMaskMc; 
			//this.mainMenu.mask = rightMenuMaskMc; 
			
			this.addEventListener(MainMenuEvent.MAIN_MENU_ITEM_CLICKED, mainMenuItemClickedHdl);
			this.addEventListener(RightMenuEvent.RIGHT_MENU_ITEM_CLICKED, rightMenuItemClickedHdl);
			
			bottomMenuContainerMc.addEventListener(BottomMenuEvent.ENG_BUTTON_CLICK, bottomMenuEngButtonHdl);
			bottomMenuContainerMc.addEventListener(BottomMenuEvent.VIET_BUTTON_CLICK, bottomMenuVietButtonHdl);
			
			bottomMenuContainerMc.addEventListener(BottomMenuEvent.MENU_BUTON_CLICK, bottomMenuItemHdl); 
			textContainerMc.addEventListener(TextTweenEvent.TWEEN_OUT_COMPLETE, textTweenOutCompleteHdl); 
			//textContainerMc.addEventListener(TextTweenEvent.TWEEN_OUT_COMPLETE, textTweenOutCompleteHdl); 
		}
		
		private function updateScrollMainMenu(): void
		{
			mainMenu.y = 333;
			verScrollMainMenu = new VerScroll(mainMenu, rightMenuMaskMc, shortVLineMc.trackMc, shortVLineMc.faceMc);	
		}
		
		private function updateScrollRightMenu(): void
		{
			rightMenu.y = 110;
			verScrollRightMenu = new VerScroll(rightMenu, thumbMaskMc, rightVLineMc.trackMc, rightVLineMc.faceMc);	
		}
		
		private function updateScrollText(): void
		{
			textContainerMc.y = 214;
			verScroll = new VerScroll(textContainerMc, textMaskMc, trackMc, faceMc);		
		}
		
		private function textTweenOutCompleteHdl(e:TextTweenEvent):void 
		{
			switch(menuItemName)
			{
				case "aboutusMc": 
					textContainHeader.text = LanguageManager.getText("ABOUT_US_TEXT_HEADER");
					textContainerMc.setText(LanguageManager.getText("ABOUT_US_ITEM_TEXT")); 
					break; 
				case "servicesMc":
					textContainHeader.text = LanguageManager.getText("SERVICES_TEXT_HEADER");
					textContainerMc.setText(LanguageManager.getText("SERVICES_ITEM_TEXT")); 
					break; 
				case "castingMc":
					textContainHeader.text = LanguageManager.getText("CASTING_TEXT_HEADER");
					textContainerMc.setText(LanguageManager.getText("CASTING_ITEM_TEXT")); 
					break; 
				case "galleryMc":
					textContainHeader.text = LanguageManager.getText("GALLERY_TEXT_HEADER");
					textContainerMc.setText(LanguageManager.getText("GALLERY_ITEM_TEXT")); 
					break; 
				case "contactMc":
					textContainHeader.text = LanguageManager.getText("CONTACT_TEXT_HEADER");
					textContainerMc.setText(LanguageManager.getText("CONTACT_ITEM_TEXT")); 
					break;
			}
			
			updateScrollText();
		}
		
		private function bottomMenuItemHdl(e:BottomMenuEvent):void 
		{
			menuItemName = e.itemName; 
			switch (e.itemName)
			{
				case "aboutusMc": 
					textContainerMc.showNextText(); 
					break; 
				case "servicesMc":
					textContainerMc.showNextText(); 
					break; 
				case "castingMc":
					textContainerMc.showNextText(); 
					break; 
				case "galleryMc":
					textContainerMc.showNextText(); 
					break; 
				case "contactMc":
					textContainerMc.showNextText(); 
					break;
			}
		}
		
		private function bottomMenuVietButtonHdl(e:BottomMenuEvent):void 
		{
			//trace("viet button clicked"); 
			LanguageManager.setLanguage("viet"); 
			updateText(); 
		}
		
		private function bottomMenuEngButtonHdl(e:BottomMenuEvent):void 
		{
			//trace("eng button clicked"); 
			LanguageManager.setLanguage("en"); 
			updateText();
		}
		
		private function rightMenuItemClickedHdl(e:RightMenuEvent):void 
		{
			var videoInfo: VideoInfo = e.videoInfo;
			videoPlayer.playVideo(videoInfo);
		}
		
		private function mainMenuItemClickedHdl(e:MainMenuEvent):void 
		{
			var albumInfo: AlbumInfo = e.albumInfo;
			rightMenu.initRightMenu(albumInfo.videoInfoArr);
			this.updateScrollRightMenu();
		}
		
		public function initApp(aInfoArr:Array): void
		{
			albumInfoArr = aInfoArr;
			mainMenu.initMainMenu(albumInfoArr);
			if (albumInfoArr.length)
			{
				var albumInfo:AlbumInfo = albumInfoArr[0];
				rightMenu.initRightMenu(albumInfo.videoInfoArr);
				this.updateScrollRightMenu();
			}
			
			this.updateScrollMainMenu();
		}
		
		public function tweenInMainText():void
		{
			textContainerMc.tweenIn(); 
		}
		
		public function playRightMenuAnim ():void
		{
			mainMenu.tweenIn(); 
		}
		
		public function showThumbStrip():void
		{
			rightMenu.showThumbs(); 
		}
		
		public function updateText():void
		{
			bottomMenuContainerMc.setText(); 
			
			switch(menuItemName)
			{
				case "aboutusMc": 
					textContainHeader.text = LanguageManager.getText("ABOUT_US_TEXT_HEADER");
					textContainerMc.setText(LanguageManager.getText("ABOUT_US_ITEM_TEXT")); 
					break; 
				case "servicesMc":
					textContainHeader.text = LanguageManager.getText("SERVICES_TEXT_HEADER");
					textContainerMc.setText(LanguageManager.getText("SERVICES_ITEM_TEXT")); 
					break; 
				case "castingMc":
					textContainHeader.text = LanguageManager.getText("CASTING_TEXT_HEADER");
					textContainerMc.setText(LanguageManager.getText("CASTING_ITEM_TEXT")); 
					break; 
				case "galleryMc":
					textContainHeader.text = LanguageManager.getText("GALLERY_TEXT_HEADER");
					textContainerMc.setText(LanguageManager.getText("GALLERY_ITEM_TEXT")); 
					break; 
				case "contactMc":
					textContainHeader.text = LanguageManager.getText("CONTACT_TEXT_HEADER");
					textContainerMc.setText(LanguageManager.getText("CONTACT_ITEM_TEXT")); 
					break;
			}
			
			updateScrollText();
		}
		public function lock():void
		{
			this.mouseEnabled = false; 
			this.mouseChildren = false; 
		}
		
		public function unlock():void
		{
			this.mouseEnabled = true; 
			this.mouseChildren = true; 
		}
		
	}

}